// 配置路由相关信息
import VueRouter from "vue-router";
import Vue from 'vue'

import Home from "../views/Home"
import Trend from "../views/Trend/Trend"
import Graph1 from "../views/Graph1"
import Graph2 from "../views/Graph2"
import Robot1 from "../views/Robot1"
import Robot2 from "../views/Robot2"
import Knowledge1 from "../views/Knowledge1"
import Knowledge2 from "../views/Knowledge2"
import Predict1 from "../views/Predict1"
import Predict2 from "../views/Predict2"
import Visualize1 from "../views/Visualize1"
import Visualize2 from "../views/Visualize2"
import Contact from "../views/Contact"
import Issue from "../views/Issue"
import Covid3d from "../views/Covid3d"

// 创建VueRouter对象
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: {title: '首页'}
  },
  {
    path: '/trend',
    component: Trend,
    meta: {title: '疫情趋势'}
  },
  {
    path: '/graph1',
    component: Graph1,
    meta: {title: '知识图谱第一组'}
  },
  {
    path: '/graph2',
    component: Graph2,
    meta: {title: '知识图谱第二组'}
  },
  {
    path: '/robot1',
    component: Robot1,
    meta: {title: '问答机器人第一组'}
  },
  {
    path: '/robot2',
    component: Robot2,
    meta: {title: '问答机器人第二组'}
  },
  {
    path: '/trend',
    component: Trend,
    meta: {title: '疫情趋势'}
  },
  {
    path: '/knowledge1',
    component: Knowledge1,
    meta: {title: '知识可视化第一组'}
  },
  {
    path: '/knowledge2',
    component: Knowledge2,
    meta: {title: '知识可视化第二组'}
  },
  {
    path: '/visualize1',
    component: Visualize1,
    meta: {title: '数据可视化第一组'}
  },
  {
    path: '/visualize2',
    component: Visualize2,
    meta: {title: '数据可视化第二组'}
  },
  {
    path: '/predict1',
    component: Predict1,
    meta: {title: '数据预测第一组'}
  },
  {
    path: '/predict2',
    component: Predict2,
    meta: {title: '数据预测第二组'}
  },
  {
    path: '/contact',
    component: Contact,
    meta: {title: '联系我们'}
  },
  {
    path: '/issue',
    component: Issue,
    meta: {title: '问题与讨论'}
  },
  {
    path: '/3d',
    component: Covid3d,
    meta: {title: 'Covid 3d'}
  },
];

Vue.use(VueRouter)
const router = new VueRouter({
  // 配置路由和组件之间的映射关系
  routes,
  mode: 'history'
});

// eslint-disable-next-line no-unused-vars
router.beforeEach((to, from, next) => {
  if (to.meta.title) document.title = 'SCUT ML - ' + to.meta.title
  else document.title = 'SCUT ML'
  next()  // 增加了全局守卫一定要添加next()
});

// 跳转页面后滚到页面顶端
router.afterEach(() => {
  window.scroll(0, 0)
});

// 将router对象传入vue实例中，也可在其他地方使用
export default router
